package disjunction.core
{
	import disjunction.extensions.view.ICamera;
	import flash.utils.Dictionary;

	/**
	 *
	 *
	 * @author Nick Wiggill
	 */
	
	public class EntityListView extends View
	{
		//List/hash of current views, used mainly for fast deletion.
		protected var _viewsByModel:Dictionary = new Dictionary();
				
		/** A list of all entity views. */
		protected var _entities:Array = [];
		
		protected var _context:*;
		
		/** (abstract) Extend for specific display list addition, if any */
		public function addEntityView(entityModel:*):void
		{
			trace('add entity view');
			var entityView:EntityView = _viewsByModel[entityModel];
			if (entityView == null)//(_entities.indexOf(entityView) == -1)
			{
				entityView = createEntityView(entityModel);
				//_entities.push(createEntity(entityModel));
				_viewsByModel[entityModel] = entityView;
				
				addPersistentEntityView(entityView);
			}
		}
		
		/** (abstract) Extend for specific display list removal, if any */
		public function removeEntityView(entityModel:*):void
		{
			var entityView:* = _viewsByModel[entityModel];
			if (entityView != null)
			{
				removePersistentEntityView(entityView);
				//_entities.splice(_entities.lastIndexOf(destroyEntity(entityModel)), 1);
				destroyEntityView(entityModel);
				delete _viewsByModel[entityModel];
			}
		}
		
		/** (abstract) */
		protected function createEntityView(entityModel:*):*
		{
			return null;
		}
		
		/** (abstract) */
		protected function destroyEntityView(entityModel:*):void
		{
			//return null;
		}
		
		/** 
		 *	(abstract) Override to add a persisting view element such as a
		 *	DOM element (JS) or DisplayObject (AS3). Ignore if custom blitting.
		 */
		protected function addPersistentEntityView(view:*):void
		{
			
		}
		
		/** 
		 *	(abstract) Override to remove a persisting view element such as a
		 * 	DOM element (JS) or DisplayObject (AS3). Ignore if custom blitting.
		 */
		protected function removePersistentEntityView(view:*):void
		{
			
		}
		
		/** Set the context to which we will either draw or renderer, depending on the
		 * 	underlying display system (blitter vs. persistent/scene graph).
		 */
		public function set context(context:*):void
		{
			_context = context;
		}
		
		/** Get the context to which we will either draw or renderer, depending on the
		 * 	underlying display system (blitter vs. persistent/scene graph).
		 */
		public function get context():*
		{
			return _context;
		}
		
		public override function update(timeDeltaMs:uint):void
		{
		}
	}
}